/**
XenSim simulates xenbal.
Copyright (C) 2006 Travis Vachon

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
package xensim;
import java.util.Vector;
import java.io.FileWriter;
import java.io.IOException;

public class MonitorEvent extends Event {

	
	private FileWriter outfile;
	private SimGlobals globals;
	private Monitor monitor;
	
	public MonitorEvent(double executionTime, Monitor monitor, SimGlobals globals, FileWriter outfile){
		super(executionTime);
		this.outfile = outfile;
		this.globals = globals;
		this.monitor = monitor;
	}
	@Override
	public void execute() throws ConfigurationError {
		for (Node node: globals.nodes){
			double total_load = monitor.getTotalLoad(node);
			for (Domain domain: node.domains){
				
				double load;
				
				load = monitor.getDomainLoad(domain);
				
				try {
					outfile.write(executionTime/SimGlobals.TIME_CONSTANT + 
							"\t" +node.name + 
							"\t" + total_load +
							"\t"+ domain.name + 
							"\t" + load + 
							"\t" + "running" + "\n");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		globals.eventQueue.add(new MonitorEvent(executionTime + SimGlobals.MONITOR_TIME, this.monitor,globals, outfile));

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
